/**
 * Universidad del Valle de Guatemala
 * Algoritmos y Bases de Datos
 * @author Rodrigo Mejia 11111
*/


import java.util.*;


public class Main {

	
	public static void main(String[] args) {
		boolean op = true;
		String num = "";
		
		Scanner scanner = new Scanner(System.in);
		Pila<Float> p1 = new StackVector<Float>();
		
		
		System.out.println("====================================CALCULADORA BASICA========================================= ");
		System.out.println("***********************************************************************************************");
		System.out.println("Instrucciones: Ingrese las operaciones que desee en formato post fix separando operadores y \n operandos por espacios. EJEMPLO: 34 6 + 5 -");
		System.out.println("***********************************************************************************************");
		System.out.println("Ingrese las operaciones: ");
		String In = scanner.nextLine();
		char[] InArray = In.toCharArray();
		
		int t = In.length();
		
		if(Character.isDigit(InArray[0]) == false || Character.isDigit(InArray[t-1])== true){
			op = false;
		}
		
		for(int x = 0; x < (t-1); x++){
			if(InArray[x]== ' ' && InArray[x+1] == ' '){
				op = false;
			}
		}
		for(int x = 0; x < (t-1); x++){
			if(InArray[x]== '+' && InArray[x+1] == '+'){
				op = false;
			}
		}
		for(int x = 0; x < (t-1); x++){
			if(InArray[x]== '-' && InArray[x+1] == '-'){
				op = false;
			}
		}
		for(int x = 0; x < (t-1); x++){
			if(InArray[x]== '*' && InArray[x+1] == '*'){
				op = false;
			}
		}
		for(int x = 0; x < (t-1); x++){
			if(InArray[x]== '/' && InArray[x+1] == '/'){
				op = false;
			}
		}
		
		if(InArray[t-2] != ' '){
			op = false;
		}
		
		if(op == true){
		
			for(int x = 0; x< t; x++){
				if(Character.isDigit(InArray[x]) == true){
					int c = InArray[x];
					c = c - 48;
					num = num.concat(""+c);
					if(InArray[x + 1] == ' '){
						float g = Float.parseFloat(num);
						p1.push(g);
						num = "";
					}
				}else if(InArray[x] == '+' && p1.size()==2){
					float f = p1.pop();
					float g = p1.pop();
					p1.push(suma(f, g));
				}else if(InArray[x] == '-' && p1.size()==2){
					float f = p1.pop();
					float g = p1.pop();
					p1.push(resta(g, f));
				}else if(InArray[x] == '*' && p1.size()==2){
					float f = p1.pop();
					float g = p1.pop();
					p1.push(multi(f, g));
				}else if(InArray[x] == '/' && p1.size()==2){
					float f = p1.pop();
					float g = p1.pop();
					p1.push(divi(g,f));
				}
			}
					
			
			System.out.print("El resultado es: "+p1.peek());
		}else{
			System.out.println("Error sintactico, intentelo de nuevo.");
		}
		
	}

	public static float suma(float d, float e){
		return (d + e);
	}
	
	public static float resta(float d, float e){
		return (d - e);
	}
	
	public static float multi(float d, float e){
		return (d * e);
	}
	
	public static float divi(float d, float e){
		return(d/e);
	}

}
